/*
 * @Author: Jim <jimjiang@gmail.com>
 * @Create time:   2016-08-02 11:43:53
 * @Last Modified by:   Jim
 * @Last Modified time: 2016-10-14 16:05:56
 * @File Name: user.js
 */

'use strict';

import React, {Component} from 'react';
import {
    View,
    StyleSheet,
    Text,
    Image,
    TouchableOpacity,
} from 'react-native';

import Swipeout from './swipeout';
import NetWorkImg from './networkImg';
import UserProfile from '../components/userProfile';

export default class User extends Component {
    constructor(props) {
        super(props);

        this.state = {};
        this._rowData = this.props.rowData;
        this._swipeoutBtns = this.props.swipeoutBtns || [
            {
                text: 'Delete',
                type: 'delete',
                onPress: () => { this.props.delData(this.props.rowData.usr_id) }
            }
        ];
    }

    render() {
        let location = []; [this._rowData.city, this._rowData.state].map(function(val){
        if(val) location.push(val);
        });
        return(
            <Swipeout 
                right={this._swipeoutBtns} 
                rowID={this.props.rowID}
                sectionID={this.props.sectionID}
                autoClose={true}
                backgroundColor={'#fff'}
                close={true}
                scroll={event => this.props.allowScroll(event)}>
                <TouchableOpacity onPress={() => this.gotoUserProfile()}>
                <View style={styles.userBox}>
                    <NetWorkImg
                        source={{ uri: this._rowData.picture.picture || 'http://s.tmatch.com/de/picssb75/7/027/1698027-1110769.jpg' }} 
                        style={styles.userBoxImg}
                    />
                    <View style={styles.userBoxLeft}>
                        <Text style={styles.userBoxLeftText}>{this._rowData.username}</Text>
                        <Text numberOfLines={1} style={styles.userBoxLeftText}>{this._rowData.age} ● { location.length ? location.join(', ') : this._rowData.country }</Text>
                        {this._rowData.disability ? 
                        <Text numberOfLines={1} style={[styles.userBoxLeftText, styles.color]}> {Lang.common_disability} : {(parseInt(this._rowData.hide_living_with) == 1 ? Lang.common_hideLivingWithTips : Share.showCheckboxLabel('local_disability', this._rowData.disability, ', '))}</Text>
                        : null}
                    </View>
                </View>
                </TouchableOpacity>
            </Swipeout>
            )
    }

    gotoUserProfile() {
        Utils.navReplaceTo(this.props.navigator, {
            name: "UserProfile",
            component: UserProfile,
            title: this._rowData.username,
            userId: this._rowData.usr_id
        });
    }
}
const styles = StyleSheet.create(Css.UserStyle);